package com.godz.frontData.index2;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.index2HpMapper;
import com.godz.pojo.index2Hp;
import org.springframework.web.bind.annotation.*;
import java.util.List;

//主页2我的奖项
@RestController
public class hpData {
    final
    index2HpMapper index2HpMapper;

    public hpData(index2HpMapper index2HpMapper) {
        this.index2HpMapper = index2HpMapper;
    }

    @GetMapping("/index2/get/index2Hp")
    public List<index2Hp> getHp(){
        return index2HpMapper.queryAllHp();
    }

    //查询单个
    @GetMapping("/index2/get/index2Hp/{intId}")
    public index2Hp getOneHp(@PathVariable("intId") Integer integer) {
        return index2HpMapper.selectOne(
                new QueryWrapper<index2Hp>().eq("id", integer)
        );
    }
    //增加一条
    @PostMapping("/index2/post/addHp")
    public String addHp(@RequestBody index2Hp hp) {
        index2HpMapper.insert(hp);
        return "insert OK";
    }
    //修改一条打字机
    @PostMapping("/index2/post/editHp")
    public String editHp(@RequestBody index2Hp hp) {
        QueryWrapper<index2Hp> wrapper = new QueryWrapper<>();
        wrapper.eq("id", hp.getId());

        index2Hp hp1 = new index2Hp();

        hp1.setHpTitle(hp.getHpTitle());
        hp1.setHpUnit(hp.getHpUnit());
        hp1.setHpCategory(hp.getHpCategory());
        hp1.setHpDate(hp.getHpDate());
        hp1.setHpLevel(hp.getHpLevel());
        hp1.setHpHtitle(hp.getHpHtitle());
        hp1.setHpCon(hp.getHpCon());
        hp1.setHpImg1(hp.getHpImg1());
        hp1.setHpImg2(hp.getHpImg2());
        hp1.setHpImg3(hp.getHpImg3());

        index2HpMapper.update(hp1, wrapper);
        return "Update OK";
    }
    //删除一条打字机
    @GetMapping("/index2/get/deleteHp/{id}")
    public String deleteHp(@PathVariable("id") Integer integer) {
        index2HpMapper.deleteById(integer);
        return "Delete Ok";
    }
    //根据id和标题信息查询荣誉
    @GetMapping("/queryHp/{title}")
    public List<index2Hp> queryStoryByTitle(@PathVariable("title") String title) {
        QueryWrapper<index2Hp> wrapper = new QueryWrapper<index2Hp>()
                .like("hp_title", title)
                .or()
                .eq("id", title);
        return index2HpMapper.selectList(wrapper);
    }
}
